package com.itcam.pro01;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author : Cammy.Wu
 * Description : 异步编排
 */

public class CompletableFutureDemo01 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask futureTask = new FutureTask(new MyThread());
        Thread thread = new Thread(futureTask);
        thread.start(); // 开启异步

        // 主线程继续做其他事情
        System.out.println("主线程做其他工作...");

        // 最后再取结果
        System.out.println(futureTask.get());
    }
}

class MyThread implements Callable<String> {

    @Override
    public String call() throws Exception {
        System.out.println("--------come in");
        return "hello Callable";
    }
}